package com.hc.satoken;

import cn.dev33.satoken.stp.StpInterface;
import com.hc.bean.SysMenuBean;
import com.hc.mapper.SysMenuMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;



@Component
public class StpInterfaceImpl implements StpInterface {


    Logger logger = LoggerFactory.getLogger(StpInterfaceImpl.class.getName());
    @Autowired
    private SysMenuMapper sysMenuMapper;

    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        logger.debug("当前登录用户ID为:"+loginId +"。。。。。。");
        if (loginId!=null ) {
         List<SysMenuBean> sysMenuBeanList =    sysMenuMapper.queryPermistionByLoginUserId(Integer.parseInt(loginId.toString()) );//如何得到当前登录用户的ID呢

            List<String> returnList =new ArrayList<>();

            for(SysMenuBean sysMenuBean:sysMenuBeanList){
                returnList.add(sysMenuBean.getPerms());
            }
            logger.debug("当前登录用户:"+loginId +"拥有的权限:"+returnList);
            return  returnList;
        }


        return null;
    }

    @Override
    public List<String> getRoleList(Object o, String s) {
        return null;
    }
}
